<template>
	<view class="container">
		<view class="patient-list">
			<view class="patient-item" :class="{ active: patient.isDefault }" v-for="patient in patientList"
				:key="patient.id" @click="selectPatient(patient)">
				<view class="patient-info">
					<view class="patient-name">{{ patient.name }}</view>
					<view class="patient-idcard">{{ patient.idCard }}</view>
					<view class="patient-phone">{{ patient.phone }}</view>
				</view>
				<view class="patient-actions">
					<text class="iconfont icon-edit" @click.stop="editPatient(patient)"></text>
					<text class="iconfont icon-check" v-if="patient.isDefault"></text>
				</view>
			</view>
		</view>

		<view class="add-patient-btn" @click="addPatient">
			<text class="iconfont icon-add"></text>
			<text>添加就诊人</text>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				patientList: [{
						id: 1,
						name: '张三',
						idCard: '110101199001011234',
						phone: '13800138000',
						isDefault: true
					},
					{
						id: 2,
						name: '张小明',
						idCard: '110101201001011234',
						phone: '13800138001',
						isDefault: false
					}
				]
			}
		},
		methods: {
			selectPatient(patient) {
				// 返回上一页并传递选中的就诊人信息
				uni.$emit('selectPatient', patient);
				uni.navigateBack();
			},
			editPatient(patient) {
				// 这里可以跳转到编辑就诊人页面
				console.log('编辑就诊人:', patient);
				uni.navigateTo({
					url: '/pages/editPatient/editPatient?id=' + patient.id
				});
			},
			addPatient() {
				// 这里可以跳转到添加就诊人页面
				uni.navigateTo({
					url: '/pages/addPatient/addPatient'
				});
			}
		}
	}
</script>

<style>
	uni-app, uni-page, uni-page-wrapper, uni-page-body {
	    height: 100%;
	}
	.container {
		background-color: #f5f5f5;
		padding-bottom: 60px;
		height: 100%;
		box-sizing: border-box;
		overflow: hidden;
		overflow-y: auto;
	}

	.patient-list {
		padding: 10px;
	}

	.patient-item {
		display: flex;
		justify-content: space-between;
		background-color: #fff;
		border-radius: 8px;
		padding: 15px;
		margin-bottom: 10px;
	}

	.patient-item.active {
		border: 1px solid #1677ff;
	}

	.patient-name {
		font-size: 16px;
		font-weight: bold;
		margin-bottom: 5px;
	}

	.patient-idcard {
		font-size: 12px;
		color: #666;
		margin-bottom: 5px;
	}

	.patient-phone {
		font-size: 12px;
		color: #666;
	}

	.patient-actions {
		display: flex;
		align-items: center;
	}

	.patient-actions .iconfont {
		font-size: 18px;
		margin-left: 15px;
	}

	.patient-actions .icon-check {
		color: #1677ff;
	}

	.add-patient-btn {
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		background-color: #fff;
		color: #1677ff;
		font-size: 16px;
		text-align: center;
		padding: 15px 0;
		border-top: 1px solid #eee;
	}

	.add-patient-btn .iconfont {
		margin-right: 5px;
	}
</style>